package com.nicecode.myshiro;

import com.nicecode.myshiro.entity.User;
import com.nicecode.myshiro.jpa.UserJPA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class controller {

    @Autowired
  private   UserJPA userJPA;


    /**
     * 获取全部数据
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<User> getList(){

        return userJPA.findAll();
    }

    /**
     * 添加和更新 数据
     * @param user
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public User save(User user){

        return userJPA.save(user);
    }


    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public List<User> delete(Integer id){

       userJPA.deleteById(id);
        return userJPA.findAll();
    }


    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String say(){

        return "Hello spring boot";
    }

}
